package org.ligson.fwc.core.event;

import org.ligson.fwc.core.entity.BasicEntity;
import org.springframework.context.ApplicationEvent;

/**
 * Created by trq on 2017/8/30.
 */
public class ModelPersistentEvent extends ApplicationEvent {
    private BasicEntity entity;
    private Type type;
    private BasicEntity oldEntity;

    /**
     * Create a new ApplicationEvent.
     *
     * @param source the object on which the event initially occurred (never {@code null})
     */
    public ModelPersistentEvent(Object source, BasicEntity entity, Type type) {
        super(source);
        this.entity = entity;
        this.type = type;
    }

    public ModelPersistentEvent(Object source, BasicEntity entity, Type type, BasicEntity oldEntity) {
        super(source);
        this.entity = entity;
        this.type = type;
        this.oldEntity = oldEntity;
    }

    public BasicEntity getEntity() {
        return entity;
    }

    public void setEntity(BasicEntity entity) {
        this.entity = entity;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }


    public BasicEntity getOldEntity() {
        return oldEntity;
    }

    public void setOldEntity(BasicEntity oldEntity) {
        this.oldEntity = oldEntity;
    }

    public enum Type {
        New, Update, Delete
    }
}
